local zhanghua = fk.CreateSkill({
    name = "sj3__zhanghua",
})
  
Fk:loadTranslationTable{
  ["sj3__zhanghua"] = "章华",
  [":sj3__zhanghua"] = "你每三次失去手牌后你可以重铸所有手牌，若失去牌的方式均不同改为可以摸三张牌。",

  ["@sj3__zhanghua"] = "章华",
  ["#sj3__zhanghua"] = "章华：你可以%arg",
  ["#sj3__zhanghua_recast"] = "重铸所有手牌",
  ["#sj3__zhanghua_draw"] = "摸三张牌",

  ["$sj3__zhanghua1"] = "",
  ["$sj3__zhanghua2"] = "",
}

  zhanghua:addEffect(fk.AfterCardsMove, {
    anim_type = "drawcard",
    on_cost = function (self, event, target, player, data)
      --技能失效也清空
      local n = player:hasSkill(zhanghua.name) and player.room:askToSkillInvoke(player,{
        skill_name = zhanghua.name,
        prompt = "#sj3__zhanghua:::"..(self.draw and "#sj3__zhanghua_draw" or "#sj3__zhanghua_recast"),
      })
      player.room:setPlayerMark(player,"sj3__zhanghua",0)
      player.room:setPlayerMark(player,"@sj3__zhanghua",0)
      return n
    end,
    on_use = function(self, event, target, player, data)
      if self.draw then
        player:drawCards(3,zhanghua.name)
      else
        player.room:recastCard(player:getCardIds("h"),player,zhanghua.name)
      end
    end,
    can_refresh = function(self, event, target, player, data)
      if player:hasSkill(zhanghua.name,true) then
        for _, move in ipairs(data) do
          if move.from == player and table.find(move.moveInfo,function (info)
              return info.fromArea == Card.PlayerHand
            end) then
              local reason = move.moveReason
              if move.moveReason == fk.ReasonPut and move.toArea == Card.Processing and move.moveVisible then
                reason = 101 --拼点
              end
              event:setCostData(self,{reason = reason})
             return true
          end
        end
      end
    end,
    on_refresh = function (self, event, target, player, data)
      local reason_table = {
        [fk.ReasonJustMove] = "移动",
        [fk.ReasonDiscard] = "弃置",
        [fk.ReasonGive] = "交出",
        [fk.ReasonPut] = "置入",
        [fk.ReasonPutIntoDiscardPile] = "置入弃牌堆",
        [fk.ReasonPrey] = "获得",
        [fk.ReasonExchange] = "交换",
        [fk.ReasonUse] = "使用",
        [fk.ReasonResponse] = "打出",
        [fk.ReasonRecast] = "重铸",
        [101] = "拼点",
      }
      local reason = event:getCostData(self).reason
      if not reason_table[reason] then return end
      local room = player.room
      room:addTableMark(player,"sj3__zhanghua",reason)
      local mark = ""
      for _, v in ipairs(player:getTableMark("sj3__zhanghua")) do
        mark = mark..reason_table[v]
      end
      room:setPlayerMark(player,"@sj3__zhanghua",mark)
      if #player:getTableMark("sj3__zhanghua") == 3 then
        self.draw = not table.find(player:getTableMark("sj3__zhanghua"),function (r)
          return #table.filter(player:getTableMark("sj3__zhanghua"),function (v)
            return v == r
          end) > 1
        end)
        if self.draw or not player:isKongcheng() then
          self:doCost(event, target, player, data)
        end
      end
    end,
  })

  return zhanghua